local Class = require('lua.lang.Class')
local OutputStream = require('lua.io.OutputStream')

--- @class PrintStream : OutputStream
--- @field out OutputStream
local PrintStream = Class {
	__extends = OutputStream
}

--- @param out OutputStream
--- @return PrintStream
function PrintStream:new(out)
	--- @type PrintStream
	local o = {}
	o.out = out
	return setmetatable(o, PrintStream)
end

--- @param b number
--- @return void
function PrintStream:printByte(b)
	self.out:write(b)
end

--- @param c string
--- @return void
function PrintStream:printChar(c)
	self:printByte(c:byte())
end

--- @param s string
--- @return void
function PrintStream:printString(s)
	local a = s:toCharArray()
	local out = self.out
	for i = 1, #a do
		out:write(a[i])
	end
end

--- @param s string
--- @return void
function PrintStream:printStringLn(s)
	self:printString(s)
	self:printChar('\n')
end

--- @return void
function PrintStream:close()
	self.out:close()
	self.out = nil
end

return PrintStream